#include <stdio.h>
#include <stdlib.h>
#include <string.h>



#define PICTURE_NUM		13141
#define BUFFSIZE		1024

const char *tar_name = "badapple_bmp_arr.h";



int main(int argc, char** argv)
{
	FILE* fp_src = NULL;
	FILE* fp_tar = NULL;
	char file_name[BUFFSIZE];
	char buf[BUFFSIZE];
	size_t read_byte;
	size_t write_byte;
	int str_len;


	//create target file
	if((fp_tar = fopen(tar_name, "w")) == NULL)
	{
		printf("create target file error\n");
	}

	//save all data to target file
	for(int i = 0; i < PICTURE_NUM; i++)
	{
		bzero(buf, BUFFSIZE);
		bzero(file_name, BUFFSIZE);
		sprintf(file_name, "../picture/batch/%d", i + 1);
		str_len = strlen(file_name);
		file_name[str_len] = '.';
		file_name[str_len + 1] = 'c';
		file_name[str_len + 2] = '\0';

		if((fp_src = fopen(file_name, "r")) == NULL)
		{
			printf("%d picture open error\n", i);
		}

		while((read_byte = fread(buf, 1, BUFFSIZE, fp_src)) > 0)
		{
			if((write_byte = fwrite(buf, 1, read_byte, fp_tar)) != read_byte)
			{
				printf("write error\n");
			}

		}

		fclose(fp_src);
	}
	fclose(fp_tar);

	

	exit(0);
}
